package graphicView;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import model.*;

import java.util.Observable;
import java.util.Vector;

//ClassGraphicObject is built with ClassImpl object. Run ClassGraphicObject.drawClass(g) where g is the graphics object of the JPanel.
/**
 * Team EBE - Elite Bombard Elephants
 * 
 * ClassGraphicObject.java is the incomplete implementation of a graphical
 * object representing the class
 * 
 */
public class ClassGraphicObject extends Observable {
	private ClassImpl classObject;
	private boolean active = false;

	/**
	 * ClassGraphicObject creates the class object
	 * 
	 * @param classObjectIn
	 *            the class object used for class implementation
	 */
	public ClassGraphicObject(ClassImpl classObjectIn) {
		this.classObject = classObjectIn;
	}

	/**
	 * getModel gets the model and returns the class object
	 * 
	 * @return classObject returns the class object
	 */
	public ClassImpl getModel() {
		return classObject;
	}

	/**
	 * activate simply activates the class object
	 */
	public void activate() {
		active = true;
	}

	/**
	 * deactivate simply deactivates the class object
	 */
	public void deactivate() {
		active = false;
	}

	/**
	 * isActive determines if a class is active
	 * 
	 * @return active returns a boolean value stating that a class object is
	 *         active
	 */
	public boolean isActive() {
		return active;
	}

	/**
	 * getHeight gets the height of the class object and returns that value
	 * 
	 * @return classObject returns the class object with the height
	 */
	public int getHeight() {
		return classObject.getHeight();
	}

	/**
	 * getWidth gets the width of the class object and returns that value
	 * 
	 * @return classObject returns the class object with the width
	 */
	public int getWidth() {
		return classObject.getWidth();
	}

	/**
	 * setHeight sets the height of the class object
	 * 
	 * @param height
	 *            the value of the height set
	 */
	public void setHeight(int height) {
		classObject.setHeight(height);
	}

	/**
	 * setWidth sets the width of the class object
	 * 
	 * @param width
	 *            the value of the width set
	 */
	public void setWidth(int width) {
		classObject.setWidth(width);
	}

	/**
	 * getoX gets the value of the x origin of the class object
	 * 
	 * @return classObject returns the class object with the x origin
	 */
	public int getoX() {
		return classObject.getoX();
	}

	/**
	 * setoX sets the value of the x origin of the class object
	 * 
	 * @param oX
	 *            the value of the x origin is set
	 */
	public void setoX(int oX) {
		classObject.setoX(oX);
	}

	/**
	 * getoY gets the value of the y origin of the class object
	 * 
	 * @return classObject returns the class object with the y origin
	 */
	public int getoY() {
		return classObject.getoY();
	}

	/**
	 * setoY sets the value of the y origin of the class object
	 * 
	 * @param oY
	 *            the value of the y origin is set
	 */
	public void setoY(int oY) {
		classObject.setoY(oY);
	}

	/**
	 * sendToInspector sends the class object to the inspector and notifies the
	 * observers
	 */
	public void sendToInspector() {
		System.out.println("bleck");
		setChanged();
		notifyObservers(this.classObject);
	}

	/**
	 * getAnchorPoints gets the anchor points for the class objects and returns
	 * the class object with the anchor points
	 * 
	 * @return classObject returns the class object with the anchor points
	 *         attatched
	 */
	public Vector<AnchorPoint> getAnchorPoints() {
		return classObject.getAnchorPoints();
	}

	/**
	 * drawClass draws the classes for the project
	 * 
	 * @param g
	 *            the graphics used to draw the classes
	 * @param relationshipActive
	 *            boolean value to determine if a relationship is active
	 */
	public void drawClass(Graphics g, Boolean relationshipActive) {
		classObject.updateSize();
		classObject.updateAnchors();
		Font title = new Font("serif", Font.PLAIN, 20);
		Font attr = new Font("serif", Font.PLAIN, 12);
		int oX = classObject.getoX();

		g.setColor(Color.white);
		g.fillRect(oX, classObject.getoY(), classObject.getWidth(),
				classObject.getHeight());
		g.setColor(Color.lightGray);
		g.fillRect(oX, classObject.getoY(), classObject.getWidth(), 20);

		g.setColor(Color.black);
		g.drawRect(oX, classObject.getoY(), classObject.getWidth(),
				classObject.getHeight());

		g.setFont(title);
		int ydisp = classObject.getoY() + 15;

		g.drawString(classObject.getName(), oX + 5, ydisp);

		// y displacement starts from oY + the size of the title box, we should
		// make this deterministic later

		g.setFont(attr);

		for (AttributeImpl a : classObject.getAttributes()) {
			ydisp += 17;
			g.drawString(a.toString(), oX + 5, ydisp);
		}

		ydisp += 5;
		g.drawLine(oX, ydisp, oX + 200, ydisp);

		for (OperationImpl o : classObject.getOperations()) {
			ydisp += 17;
			g.drawString(o.toString(), oX + 5, ydisp);
		}

		if (relationshipActive) {
			for (AnchorPoint ap : classObject.getAnchorPoints()) {
				g.setColor(Color.PINK);
				g.fillOval(ap.x - 5, ap.y - 5, 10, 10);
			}
			g.setColor(Color.BLACK);
		}
	}
}
